package com.example.shopping_mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shopping_mall.R;
import com.example.shopping_mall.bean.UiGoodFreshBean;

import java.util.List;

//新鲜好物列表
public class GoodFreshAdapter extends RecyclerView.Adapter<GoodFreshAdapter.GoodFreshHolder>{

    private Context context;
    private List<UiGoodFreshBean> freshBeanList;

    public GoodFreshAdapter(Context context) {
        this.context = context;
    }

    public void setFreshBeanList(List<UiGoodFreshBean> freshBeanList) {
        this.freshBeanList = freshBeanList;
    }

    @NonNull
    @Override
    public GoodFreshHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new GoodFreshHolder(LayoutInflater.from(context).inflate(R.layout.good_fresh_things_list_item,null));
    }

    @Override
    public void onBindViewHolder(@NonNull GoodFreshHolder holder, int position) {
        holder.goodfreshImage.setImageBitmap(freshBeanList.get(position).getGoodfreshImage());
        holder.goodfreshCommodity.setText(freshBeanList.get(position).getGoodfreshCommodity());
        holder.goodfreshPrice.setText(String.valueOf(freshBeanList.get(position).getGoodfreshPrice()));
    }

    @Override
    public int getItemCount() {
        return null==freshBeanList?0:freshBeanList.size();
    }

    class GoodFreshHolder extends RecyclerView.ViewHolder{

        ImageView goodfreshImage;
        TextView goodfreshCommodity;
        TextView goodfreshPrice;

        public GoodFreshHolder(@NonNull View itemView) {
            super(itemView);

            goodfreshImage=itemView.findViewById(R.id.good_fresh_things_image);
            goodfreshCommodity=itemView.findViewById(R.id.good_fresh_things_commodity);
            goodfreshPrice=itemView.findViewById(R.id.good_fresh_things_price);

        }
    }
}
